package commons.util;

import java.io.*;

/**
 * @author Susanta Tewari
 * @version version
 * @history Created on 10/21/13.
 * @since since
 */
public class IOUtil {

    public static Object unMarshall(File file)
            throws FileNotFoundException, IOException, ClassNotFoundException {

        Object obj;

        try (ObjectInputStream ois = new ObjectInputStream(new FileInputStream(file))) {
            obj = ois.readObject();
        }

        return obj;
    }

    public static void marshall(File file, Object obj) throws FileNotFoundException, IOException {

        FileOutputStream fos = new FileOutputStream(file);

        try (ObjectOutputStream oos = new ObjectOutputStream(fos)) {
            oos.writeObject(obj);
        }
    }
}
